package pers.li.service;

import pers.li.dao.PartnerDao;
import pers.li.model.Partner;
import pers.li.utils.JedisUtils;
import pers.li.utils.JsonUtil;
import redis.clients.jedis.Jedis;

import java.util.List;

public class PartnerService {
    private final PartnerDao partnerDao = new PartnerDao();
    private final Jedis jedis = JedisUtils.getJedis();

    public List<Partner> getPartners() {
        List<Partner> partners = null;
        if (jedis.exists("partners")) {
            partners = JsonUtil.parseList(jedis.get("partners"), Partner.class);
        } else {
            partners = partnerDao.getPartners();
            jedis.set("partners", JsonUtil.toJsonString(partners));
        }
        return partners;
    }
}
